package com.glxy.controller;

import com.alibaba.fastjson.JSON;
import com.glxy.bean.Brand;
import com.glxy.servlet.BrandServiceImpl;
import com.glxy.servlet.BrandService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;

@WebServlet("/selectAllBrandsServlet")
public class SelectAllServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        BrandService servlet = new BrandServiceImpl();
        ArrayList<Brand> brands = servlet.selectAllBrand();

        String brandJson = JSON.toJSONString(brands);

        response.setContentType("text/html");
        response.setCharacterEncoding("utf8");
        response.getWriter().println(brandJson);

    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);
    }
}
